/*
 * Andy Hains
 * CS426 Project 2
 * Due: 11/22/2011
 */

/*
 * File:  buffer.h
 * --------------------
 * Header file for the buffer.
 *
 * The buffer is intended to be its own modular entity that can be reused by other
 * programs.
 *
 * The insert_item and remove_item functions are synchronized to avoid race
 * conditions and so as to not go beyond the bounds of the buffer.
 */

#ifndef BUFFER_H
#define BUFFER_H

#define BUFFER_SIZE 8

/*
 * Type:  buffer_item_t
 * --------------------
 * The data type that will be stored in the buffer.
 */
typedef unsigned char buffer_item_t;

/*
 * The input and output indexes
 */
int buffer_in, buffer_out;


/*
 * Function:  buffer_init
 * --------------------
 * Initialize the buffer.
 *
 * returns: 0 for success
 *          otherwise returns an error code
 */
int buffer_init( void );

/*
 * Function:  buffer_cleanup
 * --------------------
 * Destroys the semaphores and mutexes associated with the buffer.
 * Used when finished with the buffer.
 *
 * returns: 0 for success
 *          otherwise returns an error code
 */
int buffer_cleanup( void );

/*
 * Function:  insert_item
 * --------------------
 * Inserts an item into the buffer.
 * Synchronized with remove_item to avoid race conditions and to not go over the
 * bounds of the buffer.
 *
 * returns: 0 for success
 *         -1 indicates an error condition
 */
int insert_item( buffer_item_t );

/*
 * Function:  remove_item
 * --------------------
 * Removes an item from the buffer.
 * Synchronized with insert_item to avoid race conditions and to not go over the
 * bounds of the buffer.
 *
 * returns: 0 for success
 *         -1 indicates an error condition
 */
int remove_item( buffer_item_t* );

#endif /* BUFFER_H */

